<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\mill\model;

use think\Model;
use app\admin\model\Config as ConfigModel;
use think\Db;

/**
 * 前端接口模型
 */
class App extends Model
{

    //app页面
    public static $page = [
        //1级
        'wh'                =>  '仓库',
        'quality'           =>  '质检',
        'address'           =>  '发货',
        'speed'             =>  '生产',

        //2级

    ];
    // 配置app菜单
    public static function getMenu($pid = 0,$user = []){

        $menus = [];

        if(!empty($pid)){

            $page = self::$page;
            $menu = ['join','out','inventory','detail'];

            switch ($pid){
                case 4://铝卷库
                    $menu = ['join_lc','out_lc','inventory','detail'];
                    break;
                case 5://铝板库
                    $menu = ['join_lb','out_lb','inventory_lb','detail'];
                    break;
                case 8://稀油库
                    $menu = ['join_t_color','join_t_order','out_p_order','out_p_color','also_p','also_p_order','inventory','direct_join','direct_out','direct_also','detail'];
                    break;
                //油漆库
                case in_array($pid,ColorModel::$type_pid_arr):
                    $menu = ['join_p','out_p_order','out_p_color','also_p','also_p_order','inventory','direct_join','direct_out','direct_also','detail'];
                    break;
            }

            if(!empty($menu)){
                foreach ($menu as $m){
                    $menus[] = [
                        'id'        =>  0,
                        'pid'       =>  $pid,
                        'page'      =>  $m,
                        'title'     =>  $page[$m],
                        'menu'      =>  [],
                    ];
                }
            }

        }
        else{

            $where = [
                ['status','=',1],
                ['is_mill_role','=',1],
            ];

            //获取角色权限
            if(!empty($user['group_ids']))$where[] = ['id','in',$user['group_ids']];

            $group = Db::name('admin_user_group')->where($where)->order('give_sort asc,sort asc')->select();

            foreach ($group as $v){
                //一级菜单
                $menu = [
                    'id'        =>  $v['id'],
                    'pid'       =>  0,
                    'page'      =>  $v['app_page'],
                    'title'     =>  $v['give_title'],
                    'is_color'  =>  $v['is_color'],
                    //'menu'      =>  self::getMenu($v['id']),//二级菜单
                    'menu'      =>  [],//二级菜单
                ];

                $menus[] = $menu;
            }
        }

        return $menus;
    }

}
